﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OreSystem.Entities;
using OreSystem.BLL;
namespace MainFrom {
    public partial class EditPassWordForm : Form {
        public User User { get; set; }
        private UserBLL userBll = new UserBLL();
        public EditPassWordForm() {
            InitializeComponent();
        }

        private void EditPassWordForm_Load(object sender, EventArgs e) {
            lbl_msg.ForeColor = Color.Red;
        }

        private void button1_Click(object sender, EventArgs e) {
            string pw = txt_pw.Text;
            string newpw = txt_newpw.Text;
            string newpw2 = txt_newpw2.Text;
            if (string.IsNullOrEmpty(pw)){
                txt_pw.Focus();
                lbl_msg.Text = "请输入原始密码";
                return;
            }
            if (userBll.GetMd5Pw(pw, User.UserName) != User.PassWord) {
                txt_pw.Focus();
                lbl_msg.Text = "原始密码不对！";
                return;
            }
            if (newpw != newpw2) {
                txt_newpw.Focus();
                lbl_msg.Text = "两次密码输入不一致";
                return;
            }
            User.PassWord = newpw;
            try {
                userBll.Save(User);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex) {

                MessageBox.Show("出错了请联系管理员，错误信息："+ex.Message);
            }
        }
    }
}
